const {resolve} = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  entry: './src/index.js',
  output: {
    filename: "bundle.js",
    path: resolve(__dirname, 'build')
  },
  module: {
    rules: [
      {
        test: /\.css$/, use: ['styles-loader', 'css-loader']
      },
      {
        test: /\.(jpg|png|jpeg|gif)/,
        loader: 'url-loader',  // 依赖file-loader也要装
        options: {
          limit: 8 * 1024,  //图片大小不超过8kb,用base64编码
          name: '[hash:10].[ext]'  // 文件名
        }
      },
      {
        test: /\.html$/,
        loader: 'html-loader',  // 处理html中的图片资源(imgs),从而能被url-loader处理
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin(
      {template: "./src/index.html"}
    )
  ],
  mode: "development"
}